package com.jxt.myjxtmanager.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jxt.myjxtmanager.BaseFragment;
import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.db.SaleUser;
import com.jxt.myjxtmanager.db.SaleUserModel;
import com.jxt.myjxtmanager.manager.ActivityStack;
import com.jxt.myjxtmanager.ui.activity.AboutActivity;
import com.jxt.myjxtmanager.ui.activity.ChangePswActivity;
import com.jxt.myjxtmanager.ui.activity.FeedBackActivity;
import com.jxt.myjxtmanager.ui.activity.LoginActivity;
import com.jxt.myjxtmanager.ui.activity.MyInfoActivity;

/**
 * Created by qm on 2017/2/8 0008.
 */
public class MineFragment extends BaseFragment {

    private TextView tv_change_psw;
    private TextView tv_mine_info;
    private TextView tv_about_us;
    private Button bt_logout;
    private TextView tv_feedback;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine_layout;
    }

    @Override
    protected void initView() {
        tv_change_psw = (TextView) mView.findViewById(R.id.tv_change_psw);
        tv_mine_info = (TextView) mView.findViewById(R.id.tv_mine_info);
        tv_about_us = (TextView) mView.findViewById(R.id.tv_about_us);
        bt_logout = (Button) mView.findViewById(R.id.bt_logout);
        tv_feedback = (TextView) mView.findViewById(R.id.tv_feedback);
        tv_change_psw.setOnClickListener(this);
        tv_mine_info.setOnClickListener(this);
        tv_about_us.setOnClickListener(this);
        bt_logout.setOnClickListener(this);
        tv_feedback.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_change_psw://修改密码
                getActivity().startActivity(new Intent(getActivity(), ChangePswActivity.class));
                break;
            case R.id.tv_mine_info://我的信息
                getActivity().startActivity(new Intent(getActivity(), MyInfoActivity.class));
                break;
            case R.id.tv_about_us://关于我们
                getActivity().startActivity(new Intent(getActivity(), AboutActivity.class));
                break;
            case R.id.tv_feedback:
                SaleUser saleUser = SaleUserModel.getInstance().loadCurrentSaleUsers();
                Bundle passBun = new Bundle();
                passBun.putLong("user_id", saleUser.getUser_id());
                getActivity().startActivity(new Intent(getActivity(), FeedBackActivity.class).putExtras(passBun));
                break;
            case R.id.bt_logout://退出登录
                httpLogout();
                break;
        }
    }


    /**
     * 这里退出不需要通知后台
     */
    private void httpLogout() {
        // RongTest.clearMessages(String.valueOf(driverInfo.getId()));
        //RongTest.disconnect();
        SaleUser saleUser = SaleUserModel.getInstance().loadCurrentSaleUsers();
        saleUser.setToken("");
        SaleUserModel.getInstance().insertOrReplace(saleUser);
        // MessageTaskModel.getInstance().deletemessageAll();//清空消息
        ActivityStack.getInstance().popAllActivity(true);
        getActivity().startActivity(new Intent(getActivity(), LoginActivity.class));
        getActivity().finish();
    }

}
